package com.dk.fectory;

import com.dk.service.CodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author LTZ
 * @create 2023/5/10
 */
@Component
public class CodeFectory implements ApplicationRunner {

    @Autowired
    List<CodeService> list = new ArrayList<>();
    public static Map<String,CodeService> map = new HashMap<>();

    @Override
    public void run(ApplicationArguments args) throws Exception {
        for (CodeService code : list) {
            Class<? extends CodeService> aClass = code.getClass();
            //从注解中获取name的值
            String s = aClass.getAnnotation(CodeType.class).codeType();
            map.put(s, code);
        }
    }
}